import BUS_EVENT_KEYS from './constants/BUS_EVENT_KEYS'
import parentDataMsgHandle from '../parentDataMsgHandle'
import router from '@jsjn/micro-core-router'

export function bind() {
    /**
     * 接收父级的 props
     *  - 事件驱动
     *  - 初始化获取 (保活后，不再获取)
     */
    window.$wujie?.bus.$on(BUS_EVENT_KEYS.UPDATE_PROPS, parentDataMsgHandle)
    if (window.$wujie?.props) {
        parentDataMsgHandle(window.$wujie?.props)
    }
}

export function unbind() {
    // 微应用失活，保留离开的路由状态
    window['__LAST_ROUTE__'] = router.currentRoute.value

    window.$wujie?.bus.$off(BUS_EVENT_KEYS.UPDATE_PROPS, parentDataMsgHandle)
}
